package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.model.databaseobject.UserDo;

import org.litepal.crud.DataSupport;

import rx.Observable;
import rx.Subscriber;

/**
 * 用户信息保存
 * Created by guilin on 16/3/16.
 */
final class UserSaveOnSubScribe implements Observable.OnSubscribe<Boolean> {

    private final UserDo userDo;

    public UserSaveOnSubScribe(UserDo userDo) {
        this.userDo = userDo;
    }

    @Override
    public void call(Subscriber<? super Boolean> subscriber) {
        if (userDo != null) {
            DataSupport.deleteAll(UserDo.class);
            if (!subscriber.isUnsubscribed()) {
                subscriber.onNext(userDo.save());
            }
        }
        subscriber.onCompleted();
    }
}
